/** 注释
 * @Name 组件入口
 * @Author FiveXu
 * @Description 组件入口
 * @Date 2021-06-21 14:35
 */
import { App } from 'vue'
import initDirective from './directive'

export { Message as FxMessage } from './directive/message/globalMessage'
export { Notify as FxNotify } from './directive/notify/globalNotify'
export { Confirm as FxConfirm } from './directive/confirm/globalConfirm'
export { Loading as FxLoading } from './directive/loading/globalLoading'

const initTeleport = () => {
  const teleportId = ['dialog']
  teleportId.forEach((item: string) => {
    const dom = document.createElement('div')
    dom.id = `fx-${item}`
    document.body.append(dom)
  })
}

export default {
  install: (app: App): void => {
    initTeleport()
    const requireComponent = import.meta.globEager('../base/**/*.vue')
    Object.keys(requireComponent).forEach((filePath: string) => {
      const file: string = filePath.split('/').pop() || ''
      const disabled = ['directive', 'rateItem', 'countScrollItem', 'selectTransition', 'paginationInput', 'paginationNext', 'paginationPages', 'paginationPrevious', 'paginationSelect', 'paginationTotal']
      if (file === '' || disabled.includes(file)) return
      const fileName: string = file.replace(/\.\w+$/, '')
      const toUpper = fileName.slice(0, 1).toUpperCase() + fileName.slice(1)
      const componentConfig = requireComponent[filePath]
      app.component(`fx${toUpper}`, componentConfig.default)
    })
    initDirective(app)
  }
}
